package Comunicator;

import Entities.Scene;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import multiplayer.RendererOtrosClientes;

public class InputComunicatorOtrosClientes extends Thread implements InputComunicator{
    private String ip;
    private RendererOtrosClientes rendererOtrosClientes;

    InputComunicatorOtrosClientes(String ip, RendererOtrosClientes rendererOtrosClientes) {
        this.ip = ip;
        this.rendererOtrosClientes = rendererOtrosClientes;
    }

    @Override
    public void run() {
        try {
            ServerSocket serverSocket = new ServerSocket(5003);
            while(true){
                try {       
                    Socket socket = serverSocket.accept();
                    
                    InputStream iStream = socket.getInputStream();
                    ObjectInputStream i = new ObjectInputStream(iStream);
                    Scene scene = (Scene) i.readObject();
                    rendererOtrosClientes.setScene(scene);
                } catch (Exception ex) {
                    Logger.getLogger(InputComunicatorOtrosClientes.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(InputComunicatorOtrosClientes.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
